<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--view层-->
<div id="app">
  <h1>总价格:{{books[0].price+books[1].price+books[2].price+books[3].price}}</h1>
  <h1>总价格:{{books[0].price}}</h1>
  <h1>总价格:{{price}}</h1>
  <h1>总价格:{{totalPrice}}</h1>
</div>
<!--viewModel层-->
<script src="../../js/vue.js"></script>
<!--model层-->
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: '计算属性的性能不methods的性能好的多',
      books: [
        {id: 111, name: "代码大全", price: 100},
        {id: 112, name: "深入理解计算机原理", price: 100},
        {id: 110, name: "现代操作系统", price: 100},
      ]
    }, computed: {
      // 计算属性有缓存,性能比methods好
      price: function () {
        //高阶函数filter map reduce
        // return this.books.reduce()

        let result = 0;
        for (let i = 0; i < this.books.length; i++) {
          result += this.books[i].price
        }
        return result
      },
      totalPrice: function () {
        let result = 0;
        for (let i = 0; i < this.books.length; i++) {
          result += this.books[i].price
        }
        return result
      }
    }, methods: {
      test: function (msg) {
        //声明方法
      }
    }, created: function () {
      //生命周期
    }, mounted: function () {
      //生命周期
    }
  })
</script>
</body>
</html>